<?php
namespace app\index\controller;
use think\Db;
use my\Front;
class Api extends Base
{
  //上传图片
  function upimg($dir='default',$thumb=0){
    if(is_post()){
        //普通上传
        $thumb = $thumb ? true : false;
        $path = com_up_pic($dir, 'file', $thumb);
        if(Front::$config['r']==1){
          $rs = [
            'code' => 1,
            'msg'  => Front::$config['msg'],
            'data' => ['src'=>'','title'=>''],
          ];
        }else{
          $rs = [
            'code' => 0,
            'msg'  => '上传成功!',
            'data' => ['src'=>"/".$path,'title'=>''],
          ];
        }
        exit(json_encode($rs));
    }
  }

  # 更新表的排序
  function sorts(){
      $value = (int)input('value');
      $id = input('id');
      $table = input('table');
      if(is_int($value)){
        Db::name($table)->update(['id'=>$id,'sort'=>$value]);
      }else{
        com_error('请填写数字');
      }
      com_check(['suc_msg'=>'更新成功!','suc_js'=>'alert|reload']);
  }
}
